<script setup>
  import { watch } from 'vue';
import useTodoStore from '../store/todos';
  const todos = useTodoStore()
  // console.log(todos.list);
  const hChange = (id) => {
    todos.changeDone(id)
  }
  const hDel = (id) => {
    todos.del(id)
  }
  watch(todos,() => {
    localStorage.setItem('todos',JSON.stringify(todos.list))
  })
</script>

<template>
  <section class="main">
    <input @click="todos.checkedAll(!todos.isAll)" id="toggle-all" class="toggle-all" type="checkbox" :checked="todos.isAll" />
    <label for="toggle-all">Mark all as complete</label>
    <ul class="todo-list">
      <li v-for="item in todos.showList" :key="item.id" :class="{ completed:item.done }">
        <div class="view">
          <input @change="hChange(item.id)" class="toggle" type="checkbox" :checked="item.done" />
          <label>{{ item.name }}</label>
          <button @click="hDel(item.id)" class="destroy"></button>
        </div>
        <input class="edit" value="Create a TodoMVC template" />
      </li>
    </ul>
  </section>
</template>

<style lang="less" scoped></style>
